//
//  ForumButton.m
//  luntan
//
//  Created by dlios on 15/10/23.
//  Copyright © 2015年 dlios. All rights reserved.
//

#import "ForumButton.h"
@implementation ForumButton

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        
        [self creatControll];
    }
    return self;
}
-(void)creatControll
{
    self.array = [NSMutableArray arrayWithObjects:@"爱车俱乐部",@"地方分会",@"人 车 生活", nil];
    for (int i = 0; i < 3; i ++) {
        
        self.button =[UIButton buttonWithType:UIButtonTypeCustom];
        self.button.frame = CGRectMake(i * (mainScreen_Width / 3 ), 0, mainScreen_Width  / 3 - 2, 125 * suitableScreen_Height);
        [self.button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.button.tag = i;
        [self addSubview:self.button];
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20 * suitableScreen_Width, 15 *suitableScreen_Height, 80 *suitableScreen_Width, 80 *suitableScreen_Height)];
        self.imageView.layer.cornerRadius = 40. * suitableScreen_Width;
        self.imageView.layer.masksToBounds = YES;
        self.imageView.layer.borderColor = [UIColor whiteColor].CGColor;
        self.imageView.backgroundColor = [UIColor colorWithWhite:0.949 alpha:1.000];
        self.imageView.layer.borderWidth = 1;
        NSString *str = [NSString stringWithFormat:@"iconfont-%d",i + 1];
        [self.imageView setImage:[UIImage imageNamed:str]];
        self.imageView.contentMode = UIViewContentModeCenter;
        
        [self.button addSubview:self.imageView];
        self.lable = [[UILabel alloc]initWithFrame:CGRectMake(20 *suitableScreen_Width, 100 *suitableScreen_Height, 80 *suitableScreen_Width, 20 *suitableScreen_Height)];
        self.lable.text = [self.array objectAtIndex:i];
        self.lable.font = [UIFont systemFontOfSize:14];
        self.lable.textAlignment = NSTextAlignmentCenter;
        self.lable.textColor = [UIColor colorWithRed:0.596 green:0.612 blue:0.624 alpha:1.000];
        [self.button addSubview:self.lable];

    }
    for (int i = 1; i < 3; i++) {
        
        self.line = [[UILabel alloc]initWithFrame:CGRectMake((mainScreen_Width  / 3 - 2) * i + (i - 1)* 2, 0, 2 *suitableScreen_Width, 125 *suitableScreen_Height) ];
        [self.line setBackgroundColor:[UIColor colorWithWhite:0.925 alpha:1.000]];
        [self addSubview:self.line];
        
    }
    
    
}
- (void)buttonClick:(UIButton *)button
{
    
    [self.delegate touch:button];
}
@end
